package dwl;

import static org.junit.Assert.assertTrue;
import robocode.control.events.RoundStartedEvent;
import robocode.control.testing.RobotTestBed;

/**
 * Illustrates JUnit testing of Robocode robots. This test simply verifies that the numbers
 * generated from randomGenerator in dwl.RobotFighter is indeed random.
 * 
 * @author David Lin
 */
public class TestRandomGenerator extends RobotTestBed {

  /**
   * Specifies that RobotFighter and SpinBot are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SpinBot,dwl.RobotFighter";
  }

  /**
   * This test runs for 1 round.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 1;
  }

  /**
   * Asserts that randomly generated numbers are different, and thus, are random most of the time.
   * 
   * @param event Details about the started battle.
   */
  @Override
  public void onRoundStarted(RoundStartedEvent event) {
    RobotFighter robot = new RobotFighter();
    double[] numbers = new double[10]; // An array to store randomly generated numbers

    for (int i = 0; i < 10; i++) {
      // Store the randomly generated numbers into the array
      numbers[i] = robot.randomGenerator();
    }

    for (int i = 0; i < 10; i++) {
      for (int j = i + 1; j < 10; j++) {
        assertTrue("No randomly generated numbers are the same", numbers[i] != numbers[j]);
      }
    }
  }

}
